package main

import "fmt"

func letterCombinations(digits string) []string {
	var res []string
	var list []byte
	m := map[int]string{
		0: "",
		1: "",
		2: "abc",
		3: "def",
		4: "ghi",
		5: "jkl",
		6: "mno",
		7: "pqrs",
		8: "tuv",
		9: "wxyz",
	}

	if digits == "" {
		return res
	}

	var helper func(list []byte, index int)
	helper = func(list []byte, index int) {
		if len(list) == len(digits) {
			res = append(res, string(list))
			return
		}

		letters := m[int(digits[index]-'0')] //digits[index]-'0' 意思是byte转int，直接int(digits[index])会返回byte的码点值，引发错误结果
		for i := 0; i < len(letters); i++ {  //每个数字对应的字母长度是不一样的，所以这里要用len(letters)
			list = append(list, letters[i])
			helper(list, index+1) //index指的是当前处理的数字在digits的索引值
			list = list[:len(list)-1]
		}
	}
	helper(list, 0)
	return res
}

func main() {
	fmt.Println(letterCombinations("43"))
}
